package cn.bulgat.spring.web.config;

import cn.bulgat.common.id.IIdGenerator;
import cn.bulgat.common.id.snowflake.SnowFlakeFactory;
import cn.bulgat.common.id.snowflake.SnowFlakeLoader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class IdGeneratorConfig {

    @Bean("idGenerator")
    public IIdGenerator<Long> idGenerator() {
        Long dataCenterId = SnowFlakeLoader.getDataCenterId();
        Long machineId = SnowFlakeLoader.getMachineId();
        return SnowFlakeFactory.getSnowFlakeIdGenerator(dataCenterId, machineId);
    }
}
